﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="视频库" %>

<script runat="server">
	protected void LinqDataSource1_Inserting(object sender, LinqDataSourceInsertEventArgs e)
	{
		TVideo video = (TVideo)e.NewObject;
		video.UserName = "";
		video.UserUrl = "";
		video.AddedTime = DateTime.Now;
	}

	protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
	{
		if (e.CommandName == "CancelView")
			ListView1.SelectedIndex = -1;
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
	<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
		ContextTypeName="Xpus.YouYTube.Data.TDataContext" OrderBy="AddedTime desc" 
		TableName="TVideos" EnableInsert="True" EnableUpdate="True" 
		oninserting="LinqDataSource1_Inserting">
	</asp:LinqDataSource>
	<div>
	<asp:ListView ID="ListView1" runat="server" DataSourceID="LinqDataSource1" 
			InsertItemPosition="FirstItem" DataKeyNames="Id" 
			onitemcommand="ListView1_ItemCommand">
		<LayoutTemplate>
			<div ID="itemPlaceholderContainer" runat="server" style="">
				<div ID="itemPlaceholder" runat="server" />
			</div>
			<div style="">
				<asp:DataPager ID="DataPager1" runat="server">
					<Fields>
						<asp:NextPreviousPagerField ShowNextPageButton="false" ShowFirstPageButton="true" FirstPageText="第一页" PreviousPageText="上一页" />
						<asp:NumericPagerField ButtonCount="10" />
						<asp:NextPreviousPagerField ShowPreviousPageButton="false" ShowLastPageButton="true" LastPageText="最后一页" NextPageText="下一页" />
					</Fields>
				</asp:DataPager>
			</div>
		</LayoutTemplate>
		<InsertItemTemplate>
			<fieldset>
				<legend>添加视频</legend>
				<table>
					<tr><td>标题：</td><td><asp:TextBox ID="txtTitle" runat="server" Width="420" MaxLength="1024" Text='<%# Bind("Title") %>'></asp:TextBox></td></tr>
					<tr><td>简介：</td><td><asp:TextBox ID="txtDescription" runat="server" Width="420" Height="120" TextMode="MultiLine" Text='<%# Bind("Description") %>'></asp:TextBox></td></tr>
					<tr><td>链接地址：</td><td><asp:TextBox ID="txtSource" runat="server" Width="420" MaxLength="1024" Text='<%# Bind("Source") %>'></asp:TextBox></td></tr>
					<tr><td>嵌入代码：</td><td><asp:TextBox ID="txtEmbeddedCode" runat="server" Width="420" Text='<%# Bind("EmbeddedCode") %>'></asp:TextBox></td></tr>
				</table>
				<asp:Button runat="server" Text="添加视频" CommandName="Insert" />
			</fieldset>
		</InsertItemTemplate>
		<EmptyDataTemplate>
			<span>无数据</span>
		</EmptyDataTemplate>
		<EditItemTemplate>
			<table>
				<tr><td>标题：</td><td><asp:TextBox ID="txtTitle" runat="server" Width="420" MaxLength="1024" Text='<%# Bind("Title") %>'></asp:TextBox></td></tr>
				<tr><td>简介：</td><td><asp:TextBox ID="txtDescription" runat="server" Width="420" Height="120" TextMode="MultiLine" Text='<%# Bind("Description") %>'></asp:TextBox></td></tr>
				<tr><td>链接地址：</td><td><asp:TextBox ID="txtSource" runat="server" Width="420" MaxLength="1024" Text='<%# Bind("Source") %>'></asp:TextBox></td></tr>
				<tr><td>嵌入代码：</td><td><asp:TextBox ID="txtEmbeddedCode" runat="server" Width="420" Height="120" Text='<%# Bind("EmbeddedCode") %>'></asp:TextBox></td></tr>
				<tr><td colspan="2"><asp:CheckBox ID="chkIsDeleted" runat="server" Text="标记为删除" Checked='<%# Bind("IsDeleted") %>'></asp:CheckBox></td></tr>
			</table>
			<asp:Button runat="server" Text="保存" CommandName="Update" />
			<asp:Button runat="server" Text="取消" CommandName="Cancel" />
		</EditItemTemplate>
		<ItemTemplate>
			<p><%# ((bool)Eval("IsDeleted")) ? "[已删除]" : "" %>
			[<%# ((DateTime)Eval("AddedTime")).ToString("yyyy-MM-dd HH:mm:ss") %>]
			<strong><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></strong></p>
			<p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p>
			<p>[<asp:LinkButton runat="server" Text="查看" CommandName="Select"></asp:LinkButton>]
			[<asp:LinkButton runat="server" Text="编辑" CommandName="Edit" />]</p>
		</ItemTemplate>
		<SelectedItemTemplate>
			<p><%# ((bool)Eval("IsDeleted")) ? "[已删除]" : "" %>
			[<%# ((DateTime)Eval("AddedTime")).ToString("yyyy-MM-dd HH:mm:ss") %>]
			<strong><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></strong></p>
			<p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p>
			<div><%# Eval("EmbeddedCode") %></div>
			<p>[<asp:LinkButton runat="server" Text="关闭" CommandName="CancelView"></asp:LinkButton>]</p>
		</SelectedItemTemplate>
		<ItemSeparatorTemplate><hr /></ItemSeparatorTemplate>
	</asp:ListView>
	</div>
</asp:Content>

